package com.lewin;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sun.org.apache.xpath.internal.functions.Function;

import sun.io.Converters;
import sun.security.util.PropertyExpander.ExpandException;

import java.sql.*;
import java.util.ArrayList;

/**
 * Servlet implementation class QuanLyCuaHangBanDoTheThao
 */
@WebServlet("/QuanLyCuaHangBanDoTheThao")
public class QuanLyCuaHangBanDoTheThao extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public QuanLyCuaHangBanDoTheThao() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		
		String url="jdbc:mysql://127.0.0.1:3306/quanlycuahangbandothethao";
		try{
			//Get Connection to database
			Connection conn=DriverManager.getConnection(url,"root","061816806");
			//Create a statement
			Statement stt = conn.createStatement();
			//Execute SQL query
			int mamh=Integer.parseInt(request.getParameter("masp"));
			
			ResultSet rs =stt.executeQuery("select * from mathang where MaMH='"+mamh);
			if(rs.next())
			{
				out.println("<html><body onload=\"alert('OK')\"></body></html>");
			}
			else
			{
				out.println("<html><body onload=\"alert('Failure!')\"></body></html>");
			}
			
		}
		catch(Exception e){
			
			e.printStackTrace();
		}
		
		try {
			int dongiasp = Integer.parseInt(request.getParameter("dongiasp"));
		}
		catch(Exception e)
		{
			out.println("<html><body onload=\"alert('Đơn giá bạn phải nhập vào 1 số')\"></body></html>");
		}
		
	}

	
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	
	

}
